package com.bite.demo.controller;

import com.bite.demo.model.MessageInfo;
import com.bite.demo.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    private MessageInfoService messageInfoService;
//    private List<MessageInfo> list = new ArrayList<>();
    @RequestMapping(value = "/publish",method = RequestMethod.POST)
    public boolean publish(@RequestBody MessageInfo messageInfo) {
        System.out.println("发表留言message:"+messageInfo.getMessage());
//        list.add(messageInfo);
        messageInfoService.insertMessage(messageInfo);
        return true;
    }
    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfoService.queryMessage();
//        return list;
    }
}
